package com.zt.algorithm.sort;

public class ShellSort {
    public static void main(String args[]){
        ShellSort sort = new ShellSort();
        int a[] = new int[]{5,7,1,8,4};
        int step = a.length;
        do {
            step = step /3 + 1;
            sort.ShellSort(a,step);
        }while(step > 1);
        for (int m:a) {
            System.out.print(m + ",");
        }
    }
    public void ShellSort(int a[],int step){
        int i,j;
        for(i=step+1;i<a.length;i++){
            if(a[i] < a[i-step]){
                int temp = a[i];
                j = i-step;
                do {
                    a[j+step] = a[j];
                    j = j-step;
                }while(j>=0 && temp <a[j]);
                a[j+step] = temp;
            }
        }

    }
}
